package com.athena.controller 
{
	import com.athena.external.doithuong.MainMovie;
	import com.athena.utils.Delegate;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.events.MouseEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.ui.Mouse;
	import flash.ui.MouseCursor;
	/**
	 * ...
	 * @author ...
	 */
	public class ExchangeGift extends MainMovie
	{
		private var active : String = "";
		public function ExchangeGift(_act : String = "mobile") 
		{
			var glow:GlowFilter = new GlowFilter();
			glow.color = 0x000000;
			glow.alpha = 0.5;
			glow.blurX = 10;
			glow.blurY = 10;
			glow.quality = BitmapFilterQuality.MEDIUM;

			filters=[glow];
			
			var _w : Number = width; var _h : Number = height;
			var rectangle:Shape = new Shape();
			rectangle.graphics.beginFill(0x000000, 1);
			rectangle.graphics.drawRect((_w - Main.getInstance().config.demension.x) / 2, (_h - Main.getInstance().config.demension.y) / 2, Main.getInstance().config.demension.x, Main.getInstance().config.demension.x);
			rectangle.alpha = 0.2;
			rectangle.graphics.endFill();
			addChild(rectangle);
			setChildIndex(rectangle, 0);
			
			this.x = (Main.getInstance().config.demension.x - _w) / 2;
			this.y = (Main.getInstance().config.demension.y - _h) / 2;
			
			setupButton();
			btnclick(null, _act);
		}
		
		private function setupButton() : void {
			
			mobi_btn.addEventListener(MouseEvent.ROLL_OVER, Delegate.create(btnover, "mobile"));
			mobi_btn.addEventListener(MouseEvent.ROLL_OUT, Delegate.create(btnout, "mobile"));
			mobi_btn.addEventListener(MouseEvent.CLICK, Delegate.create(btnclick, "mobile"));
			
			gift_btn.addEventListener(MouseEvent.ROLL_OVER, Delegate.create(btnover, "gift"));
			gift_btn.addEventListener(MouseEvent.ROLL_OUT, Delegate.create(btnout, "gift"));
			gift_btn.addEventListener(MouseEvent.CLICK, Delegate.create(btnclick, "gift"));
			
			close_btn.addEventListener(MouseEvent.CLICK, close);
		}
		
		private function removeEvent() : void {
			mobi_btn.removeEventListener(MouseEvent.ROLL_OVER, Delegate.create(btnover, "mobile"));
			mobi_btn.removeEventListener(MouseEvent.ROLL_OUT, Delegate.create(btnout, "mobile"));
			mobi_btn.removeEventListener(MouseEvent.CLICK, Delegate.create(btnclick, "mobile"));
			
			gift_btn.removeEventListener(MouseEvent.ROLL_OVER, Delegate.create(btnover, "gift"));
			gift_btn.removeEventListener(MouseEvent.ROLL_OUT, Delegate.create(btnout, "gift"));
			gift_btn.removeEventListener(MouseEvent.CLICK, Delegate.create(btnclick, "gift"));
			
			close_btn.removeEventListener(MouseEvent.CLICK, close);
		}

		private function close(e : MouseEvent) : void {
			removeEvent();
			this.parent.removeChild(this);
		}
		
		private function btnover(e : MouseEvent, str: String) : void {
			Mouse.cursor = MouseCursor.BUTTON;
			if(active != str)
				(e.currentTarget as MovieClip).gotoAndStop(2);
		}
		private function btnout(e : MouseEvent, str: String) : void {
			Mouse.cursor = MouseCursor.AUTO;
			if(active != str)
				(e.currentTarget as MovieClip).gotoAndStop(1);
		}
		
		private function btnclick(e : MouseEvent, str :String) : void {
			if (active == str) return;
			active = str;
			mobi_btn.gotoAndStop(1);
			gift_btn.gotoAndStop(1);
			
			var btn : MovieClip = (str == "mobile") ? mobi_btn : gift_btn;
			btn.gotoAndStop(3);
			if (str == "mobile") {
				mobile_mc.visible = true;
				gift_mc.visible = false;
			}else {
				mobile_mc.visible = false;
				gift_mc.visible = true;
			}
		}
	}

}